package it.elis.media.library.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import it.elis.media.library.dao.UserDao;
import it.elis.media.library.model.data.Role;
import it.elis.media.library.model.data.User;
import it.elis.media.library.service.SecurityService;

public class SecurityServiceImpl implements SecurityService {

	@Autowired
	UserDao userDao;
	
	@Override
	public User login(String username, String password) throws Exception {
		User user = userDao.getUser(username);
		if (null == user) {
			throw new Exception("utente inesistente");
		} else {
			if (user.getPassword().equals(password)) {
				user.setPassword(null);
				return user;
			} else {
				throw new Exception("password errata");
			}
		}
	}

	@Override
	public List<Role> getRoles(String username) throws Exception {
		return userDao.getRoles(username);
	}

}
